local thbattle__parsee_jidu = fk.CreateSkill {

  name = "thbattle__parsee_jidu",

  tags = {},

}



thbattle__parsee_jidu:addEffect("viewas", {
  anim_type = "control",
  pattern = "dismantlement",
  card_filter = function(self, player, to_select, selected)
    if #selected == 1 then return false end
    return Fk:getCardById(to_select).color == Card.Black
  end,
  view_as = function(self, player, cards)
    if #cards ~= 1 then return nil end
    local c = Fk:cloneCard("chengguanzhifa__dismantlement")
    c.skillName = thbattle__parsee_jidu.name
    c:addSubcard(cards[1])
    return c
  end,
  enabled_at_response = function(self, player, response)
    return not response
  end
})

thbattle__parsee_jidu:addEffect(fk.BeforeCardsMove, {
  anim_type = "drawcard",
  prompt = "#thbattle__parsee_jidu_trigger-prompt",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(thbattle__parsee_jidu.name) then return false end
    for _, move in ipairs(data) do
      if move.from and move.from ~= player and player:distanceTo(move.from) == 1 and move.toArea == Card.DiscardPile
          and move.moveReason == fk.ReasonDiscard and move.proposer == player and move.skillName == "dismantlement_skill" then
        for _, info in ipairs(move.moveInfo) do
          if Fk:getCardById(info.cardId).suit == Card.Diamond then
            return true
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    for _, move in ipairs(data) do
      if move.from and move.from ~= player and player:distanceTo(move.from) == 1 and move.toArea == Card.DiscardPile
          and move.moveReason == fk.ReasonDiscard and move.proposer == player and move.skillName == "dismantlement_skill" then
        for _, info in ipairs(move.moveInfo) do
          if Fk:getCardById(info.cardId).suit == Card.Diamond then
            player.room:obtainCard(player, info.cardId, true, fk.ReasonPrey, player,
              "thbattle__parsee_jidu")
          end
        end
      end
    end
  end
})

return thbattle__parsee_jidu
